package interview.sort;

import framework.AbstractTest;
import java.util.Arrays;
import utils.Log;

public final class QuickSort extends AbstractTest {


    @Override
    public void test(String[] args) {
        super.test(args);
        int[] array = {6, 5, 2, 4,8,7,3,1};
        quickSort(array, 0, array.length-1);
        Log.vn("array:" + Arrays.toString(array));
    }





    public void quickSort(int arr[], int left, int right) {
        if (left >= right) {
            return;
        }

        int pivot = arr[left];
        while(left < right) {
            while(arr[left] <= pivot) {
                left++;
            }

            while (arr[right] >= pivot) {
                right--;
            }

            if (left < right) {
                int temp = arr[left];
                arr[left] = arr[right];
                arr[right] = temp;
            }
        }

        arr[right] =  1;
    }




}
